package me.vudu.Conflict.Listeners;



import me.vudu.Conflict.ConflictPlugin;
import me.vudu.Conflict.Listeners.Skills.SkillScreenListener;

import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.getspout.spoutapi.event.screen.ButtonClickEvent;
import org.getspout.spoutapi.player.SpoutPlayer;

 /**
  * verarbeitet Button-Ereignisse beim Teamauswahloverlay
  * @author vwendel
  *
  */
public class TeamChoiceScreenListener implements Listener{
 
 
    ConflictPlugin plugin;
 
    public TeamChoiceScreenListener(ConflictPlugin spoutMeasure) {
        plugin = spoutMeasure;
        Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
    }
 
    @EventHandler(priority = EventPriority.HIGH)
    public void onButtonClick(ButtonClickEvent event){ 
   
        SpoutPlayer player = event.getPlayer(); 
        
        ConflictPlugin.playerJoinTimestamps.put(player, player.getWorld().getFullTime());
        
        if(event.getButton().getText().equals("Team RED")){ 
            ConflictPlugin.playersRed.add(player);
            ConflictPlugin.playersBlue.remove(player);
            player.getMainScreen().closePopup();
            ConflictPlugin.updateTeamNames();
            SkillScreenListener.updatePlayerValues(player);
            ConflictPlugin.initBaseLabels(player);
            Bukkit.getServer().broadcastMessage("Player "+player.getName()+" joined Team RED!");
        }
        else if(event.getButton().getText().equals("Team BLUE")){ 
            ConflictPlugin.playersBlue.add(player);
            ConflictPlugin.playersRed.remove(player);
            player.getMainScreen().closePopup();
            ConflictPlugin.updateTeamNames();
            SkillScreenListener.updatePlayerValues(player);
            ConflictPlugin.initBaseLabels(player);
            Bukkit.getServer().broadcastMessage("Player "+player.getName()+" joined Team BLUE!");
        }
      
    }
 
}